#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
    int data;
    struct node* next;
}Node;
Node* head = NULL;
void Print()
{
    Node* temp = head;
    while (temp != NULL){
        printf("%d ",temp->data);
        temp = temp->next;
    }
    printf("\n");
}
void Delete()    
{
    Node* temp = head;
    Node* cur = temp->next;
    while (cur != NULL) {
        if(cur->data==temp->data) {
            temp->next=cur->next;
            free(cur);
            cur=temp->next;
        }
        else {
            temp=temp->next;
            cur=cur->next;
        }
    }
}

int main() {
    int n,x;
    while(scanf("%d",&n)!= EOF) {
        if(n==0){
            printf("list is empty\n");
            return 0;
        }
        Node* cur = NULL;
        for(int i=0;i<n;i++) {
            scanf("%d",&x);
            Node* new = (Node*)malloc(sizeof(Node));
            new->data = x;
            new->next = NULL;
            if(cur == NULL) {
                cur = new;
                head = new;
            } 
            else {
                cur->next = new;
                cur = cur->next;
            }
        }
        Print();
        Delete();
        Print();
    }
    return 0;
}